package com.yowasa.xiuxian.engine.battle.enemy.strategy;

import cn.hutool.core.util.ObjectUtil;
import com.google.common.collect.Lists;
import com.yowasa.xiuxian.annoations.BS;
import com.yowasa.xiuxian.engine.battle.strategy.BaseSpellStrategy;
import com.yowasa.xiuxian.entity.bo.battle.BattleContent;
import com.yowasa.xiuxian.entity.bo.battle.UserBattleContent;
import com.yowasa.xiuxian.entity.bo.user.UserBO;
import com.yowasa.xiuxian.entity.enums.ElementEnum;
import com.yowasa.xiuxian.exception.HandlerException;
import com.yowasa.xiuxian.service.helper.BattleHelper;
import com.yowasa.xiuxian.util.RandomUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.Map;

@BS(name = "祸津御建鸣神命")
@Order(1006)
@Component
public class HuoShenMing extends BaseSpellStrategy {
    @Autowired
    private BattleHelper battleHelper;

    @Override
    public ElementEnum getElement() {
        return null;
    }

    @Override
    public void action(UserBattleContent first, UserBattleContent second, BattleContent content) {
        second.getBattleInfo().setCmp(Math.max(0,second.getBattleInfo().getCmp() - second.getBattleInfo().getMp()/10));
        Map<String, Object> flag = first.getFlag();
        Object o= flag.get("无念无想");
        BigDecimal divide = new BigDecimal(first.getBattleInfo().getChp()).divide(new BigDecimal(first.getBattleInfo().getHp()),BigDecimal.ROUND_CEILING);
        if(divide.doubleValue() <= 0.6 && ObjectUtil.isNull(o)){
            content.getMsgLog().add("此身，即永恒,祸津御建鸣神命进入了恶曜影向天魔状态");
            first.getBattleInfo().setDef(first.getBattleInfo().getDef() * 2);
            first.getBattleInfo().setRes(first.getBattleInfo().getRes() * 2);
            first.getBattleInfo().setSpd((int) (first.getBattleInfo().getSpd() * 1.5));

            first.getTempBattleInfo().setDef(first.getTempBattleInfo().getDef() * 2);
            first.getTempBattleInfo().setRes(first.getTempBattleInfo().getRes() * 2);
            first.getTempBattleInfo().setSpd((int) (first.getTempBattleInfo().getSpd() * 1.5));
            first.getFlag().put("无念无想",1);
        }
        if(content.getTurn() >= 10 && Math.random() < 0.2){
            second.getBattleInfo().setChp(0);
            content.getMsgLog().add("终归——万劫——\n祸津御建鸣神命发动了无念·断绝，你鼠了");
            return;
        }
        String desc;
        Double v ;
        double random = Math.random();
        int orgAtk = first.getBattleInfo().getAtk();
        if(random < 0.2){
            desc = "万雷归葬";
            v = 2.5;
        }else if(random <0.5){
            desc = "一心无想";
            orgAtk = first.getBattleInfo().getSpell();
            v = 2.0;
        }else {
            desc = RandomUtil.choice(Lists.newArrayList("恶曜雷眼", "雷陨","雷斩·裁决","稻光随我号令"));
            v = 1.6;
        }
        int dmg;

        int def = second.getBattleInfo().getDef();
        dmg = (int) (battleHelper.calSpell(orgAtk, def) * v);
        battleHelper.autoAction(this, first, second, content, dmg, desc);
    }

    @Override
    public void limit(UserBO user) {
        throw new HandlerException("无法学习妖兽的攻击手段");
    }

    @Override
    public String limitDesc() {
        return "无";
    }

    @Override
    public String desc() {
        return  "代行雷电将军权能的人偶，在对抗威胁「永恒」之敌时展现出的形态。\n" +
                "作为雷电影践行「永恒」的协助者，她从未质疑，亦无畏惧，一直以来全力以赴，心无杂念。\n" +
                "当两个影子交叠为一时，她却只能看见在「她」本应永恒的意志上留下的无数细密的凿痕吧。既然命运注定是一场轮回，就如约定那样，向其宣战吧。\n" +
                "「此身，象征无上威严，被授予统领一国之权，凝聚了『雷电将军』的一切。\n" +
                "「自然也继承了影前行时不断失去的痛苦，以及，想要抵达永恒的决心。\n" +
                "「决心、勇气、爱慕、仇恨…都会在时间长河中变质扭曲。\n" +
                "「唯有『法则』永恒不变。」\n\n" +
                "特性 ： 噬能、即死、元素护甲 \n" +
                "人偶的攻击会使目标流失10%的mp\n当回合数大于10时，人偶有20%的几率释放 [无念·断绝] ,此招式为即死\n当人偶血量低于60%时，将会触发 [无念·无想] 状态双抗提升2倍，并使速度提升1.5倍\n" +
                "掉落物：\n 凶将之手眼,祸神之禊泪,万劫之真意,无念无想秘籍";
    }


}
